<template>
	<view class="content">
		
		<view class="address">
			<view class="address_detail">
				<view class="address_right">
					<view class="nickname_phone">
						<view class="nickname">{{ address.name }}</view>
						<view class="phone">{{ address.mobile }}</view>
		<!-- 				<view class="address_img">
							<image src="../../static/you.png" mode="aspectFit"></image>
						</view> -->
					</view>
					<view class="address_con">
						<view class="address_i">
							<image src="https://jialianxin-1301053941.cos.ap-chengdu.myqcloud.com/static/adds.png" mode="aspectFit"></image>
						</view>
						<view class="address_s" v-if="type=='store' && address.Area">
							{{ address.Area.province + address.Area.city + address.Area.region + address.detail ? address.Area.province + address.Area.city + address.Area.region + address.detail : '请选择地址' }}
						</view>
						<view class="address_s" v-else>
							{{ address.province + address.city + address.area + address.details ? address.province + address.city + address.area + address.details : '请选择地址' }}
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 选择划拨内容111 -->
		<view class="choose_transfer_box" v-if="currentTab == 0">
			<view class="choose_transfer">
				<view class="choose_transfer_wrap">
					<view class="choose_transfer_left">选择需要划拨的设备（单选）</view>
					<view class="choose_transfer_middle">
						可划拨的设备
						<text>{{ total }}</text>
						台
					</view>
					<view class="choose_transfer_right" @tap="open(2, 'right')">筛选</view>
					<openAlert ref="openAlert" :shadeClose="true" :AlertClass="AlertClass" :AlertPosition="AlertPosition">
						<view class="sreening_wrap">
							<view class="type_obj_str" v-for="(item, index) in type_obj" :key="index" @click="select_load(item)">{{ item.name }}</view>
						</view>
					</openAlert>
				</view>
			</view>
			<view class="card_list_wrap">
				<radio-group @change="changeCheckbox">
					<!-- <empty v-if="loaded === true && checkboxData.length === 0"></empty> -->
					<label class="card_item" v-for="(item, index) in checkboxData" :key="index">
						<view class="card_list">
							<view class="card_list_left">
								<view class="card_name">{{ item.activestatus_text }}</view>
								<view class="card_num">
									<text selectable="true">{{ item.sn }}</text>
								</view>
							</view>
							<radio :value="item.id.toString()" :checked="item.id === current" />
						</view>
					</label>
					<uni-load-more :status="loadingType"></uni-load-more>
				</radio-group>
			</view>
			<view class="Transfer_bottom">
				<view class="Transfer_bottom_wrap">
					<view class="Transfer_btn_wrap"><view class="Transfer_btn" @click="toTransferPeople">确定划拨</view></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import openAlert from '../../components/open-alert/open-alert.vue';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
import empty from '@/components/empty';
export default {
	components: { openAlert, uniLoadMore, empty },
	data() {
		return {
			address: {
				"name":"测试",
				"mobile":"123456789",
			},
			ids: [],
			orderId : 0,
			orderKey:0,
			total: 0,
			startend: '',
			endcode: '',
			remark: '',
			trnum: '',
			num: 0,
			checkedArr: [], //复选框选中的值
			allChecked: false, //是否全选
			AlertClass: 0,
			AlertPosition: '',
			currentTab: 0,
			top_tab: [
				{
					tab_name: '选择划拨'
				},
				{
					tab_name: '区间划拨'
				}
			],

			loaded: false,
			loadingType: 'more',
			pageNum: 1,
			limit: 10,
			type_id: 0,
			type_obj: [],
			current:0,
			checkboxData: [
				// {
				// 	card_name:'洁牙卡1-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡3-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡3-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡4-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡5-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡6-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡7-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡8-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡9-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡10-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡11-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡12-卡号',
				// 	card_num:'013404'
				// }
			],
			token:''
		};
	},
	onLoad(opt) {
		this.orderId = opt.oid
		this.orderKey = opt.key
		this.token=opt.token
		//console.log(opt)
	},
	onShow() {
		//显示内容
		this.loadData(0);
		this.loadAddress();
		
		//获取类型列表
		let params = {
			page: this.pageNum,
			limit: this.limit,
			category_id: this.type_id,
			token:this.token
		};
		// GET/api/usercenter/device/category
		var url = '/api/usercenter/device/category';
		this.Unfold_data.upload_data(params, 'GET', url, res => {
			if (res.statusCode == 200 && res.data.code == 1) {
				this.type_obj = res.data.data;
			} else {
				this.Unfold_data.showWindow(res.data.msg);
			}
		});
	},
	onReachBottom() {
		this.loadData(1);
	},
	methods: {
		//选择pos机类型
		select_load(item) {
			this.type_id = item.id;
			this.pageNum = 1
			this.loadData(3);
		},
		
		// 获取订单地址跟信息
		loadAddress(){
			var url = '/api/cshop/posorder/details';
			this.Unfold_data.upload_data({id:this.orderId,token:this.token}, 'POST', url, res => {
				if (res.statusCode == 200 && res.data.code == 1) {
					 this.address = res.data.data.addres
				}
			})
		},
		
		//分页获取好啵设备
		loadData(source) {
			//source 防止重复加载
			if (source == 0 && this.loaded) {
				return;
			}
			if (source == 1 && this.loadingType != 'more') {
				return;
			}
			if (source == 3) {
				this.checkboxData = [];
			}

			let params = {};
			if (this.type_id == 0) {
				params = {
					page: this.pageNum,
					limit: this.limit,
					token:this.token
				};
			} else {
				params = {
					page: this.pageNum,
					limit: this.limit,
					category_id: this.type_id,
					token:this.token
				};
			}
			var url = '/api/usercenter/device';
			this.Unfold_data.upload_data(params, 'GET', url, res => {
				if (res.statusCode == 200 && res.data.code == 1) {
					//赋值
					this.endcode = res.data.data.sn;
					this.total = res.data.data.total;
					if (source == 0) {
						this.loaded = true;
					}
					if (!res.data.data.rows) {
						this.loadingType = 'noMore';
					} else if (res.data.data.rows.length < this.limit) {
						this.loadingType = 'noMore';
						if (res.data.data.rows.length > 0) {
							this.checkboxData = this.checkboxData.concat(res.data.data.rows);
						}
					} else if (res.data.data.rows.length == this.limit) {
						if (res.data.data.rows.length > 0) {
							this.checkboxData = this.checkboxData.concat(res.data.data.rows);
						}
						this.pageNum = this.pageNum + 1;
					}
					this.$refs.openAlert.Close();
				} else if (res.statusCode == 200 && res.data.code == 401) {
					this.Unfold_data.showWindow(res.data.msg);
				} else {
					this.Unfold_data.showWindow(res.data.msg);
				}
			});
		},
		startends(e) {
			// console.log(e);
			this.startend = e.detail.value;
		},
		//监听划拨
		trnume(a) {
			// console.log();
			let params = {
				// T文本	是
				sn: this.startend,
				//起始编号
				num: Number(a.detail.value),
				token:this.token
			};
			var url = '/api/usercenter/device/endSn';
			this.Unfold_data.upload_data(params, 'POST', url, res => {
				if (res.statusCode == 200 && res.data.code == 1) {
					//获取截至编号
					this.endcode = res.data.data.sn;
				} else if (res.statusCode == 200 && res.data.code == 401) {
					this.Unfold_data.showWindow(res.data.msg);
				} else {
					this.Unfold_data.showWindow(res.data.msg);
				}
			});
		},
		changeTab(index) {
			this.currentTab = index;
		},
		// 多选复选框改变事件
		changeCheckbox(e) {
			this.current = e.detail.value;
		},
		submitForm(e) {
			//区间划拨
			if (!e.detail.value.startend) {
				this.Unfold_data.showWindow('起始序列号不能为空');
				return;
			}
			if (!e.detail.value.trnume) {
				this.Unfold_data.showWindow('划拨数量不能为空');
				return;
			}

			let params = {
				//开始
				sn: this.startend,
				//结束
				end: this.endcode,
				//划拨数量
				num: e.detail.value.trnume,
				token:this.token
			};
			uni.setStorageSync('par', params);
			uni.navigateTo({
				url: '/pages/transferPeople/transferPeople'
			});
		},
		toTransferRecord() {
			uni.navigateTo({
				url: '/pages/transferRecord/transferRecord'
			});
		},
		toTransferPeople() {
			if (this.current=='') {
				this.Unfold_data.showWindow('请选择设备');
				return;
			}
			let orderKey = this.orderKey;
			var url = '/api/cshop/posorder/deliver';
			this.Unfold_data.upload_data({
				"oid":this.orderId,
				"cid":this.current,
				token:this.token
			}, 'POST', url, res => {
				if (res.statusCode == 200 && res.data.code == 1) {
				     this.Unfold_data.showWindow(res.data.msg);
					 setTimeout(function () {
						  uni.setStorageSync('delete_array',orderKey);
						  uni.navigateBack({delta: 1});
					 }, 2000);
				}
			})
		},
		//打开弹出层
		open(Class, Position) {
			this.$nextTick(function() {
				this.AlertClass = Class;
				this.AlertPosition = Position;
				this.$nextTick(function() {
					this.$refs.openAlert.Show();
				});
			});
		}
	}
};
</script>

<style lang="scss">
page {
	width: 100%;
	height: 100%;
	background-color: #f5f9fc;
}
.blank {
	height: 100upx;
}
.content {
	width: 100%;
	position: relative;
	padding-bottom: 100upx;
	.address {
		width: 100%;
		margin: 0 auto;
		margin-top: 20upx;
		background: #ffffff;
		border-radius: 20upx;
		display: flex;
		align-items: center;
		justify-content: center;
		.address_no{
			width: 90%;
			margin: 0 auto;
			.address_title{
				width: 100%;
				height: 60upx;
				border-bottom: 3upx solid #ededed;
				display: flex;
				align-items: center;
				font-size: 28upx;
			}
			.addAddress {
				width: 100%;
				display: flex;
				align-items: center;
				padding: 20upx 0;
				.add_img {
					flex: 1;
					image {
						width: 60upx;
						height: 60upx;
					}
				}
				.add_name {
					flex: 6;
					color: #7c7c7c;
				}
			}
		}
		.address_detail {
			width: 90%;
			margin: 0 auto;
			display: flex;
			align-items: center;
			.address_left {
				flex: 2;
				image {
					width: 102upx;
					height: 102upx;
				}
			}
			.address_right {
				// flex: 8;
				width: 100%;
				.change_address {
					width: 100%;
					height: 60upx;
					font-size: 20upx;
					color: #9f9f9f;
					display: flex;
					align-items: center;
					justify-content: flex-end;
					border-bottom: 3upx solid #ededed;
					text{
						padding-right: 10upx;
					}
					.address_img{
						display: flex;
						align-items: center;
						justify-content: center;
						image{
							width: 25upx;
							height: 25upx;
						}
					}
				}
				.nickname_phone {
					width: 100%;
					height: 80upx;
					display: flex;
					align-items: center;
					.nickname {
						flex: 1;
					}
					.phone {
						flex: 3;
						color: #7c7c7c;
					}
					.address_img{
						display: flex;
						align-items: center;
						justify-content: center;
						image{
							width: 25upx;
							height: 25upx;
						}
					}
				}
				.address_con {
					width: 100%;
					display: flex;
					align-items: center;
					padding-bottom: 30upx;
					.address_i{
						padding-right: 15upx;
						display: flex;
						align-items: center;
						justify-content: center;
						image{
							width: 30upx;
							height: 30upx;
						}
					}
					.address_s{
						font-size: 24upx;
						display: -webkit-box;
						overflow: hidden;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
					}
				}
			}
		}
	}
	.top_tab {
		width: 100%;
		height: 100upx;
		border-top: 6upx solid #dadada;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 10;
		background-color: #ffffff;
		display: flex;
		align-items: center;
		justify-content: center;
		// margin-top: 86upx;
		.top_tab_wrap {
			flex: 9;
			display: flex;
			align-items: center;
			justify-content: center;
			.tab_item {
				flex: 1;
				display: flex;
				align-items: center;
				justify-content: center;
				.item_name {
					padding: 20upx 0;
					border-bottom: 6upx solid #ffffff;
				}
				.item_active {
					padding: 20upx 0;
					border-bottom: 6upx solid #1a80da;
					color: #1a80da;
				}
			}
		}
		.top_tab_right {
			flex: 1;
			image {
				width: 60upx;
				height: 60upx;
			}
		}
	}
	.choose_transfer_box {
		width: 100%;
		//margin-top: 100upx;
		.choose_transfer {
			width: 100%;
			height: 90upx;
			display: flex;
			align-items: center;
			justify-content: center;
			.choose_transfer_wrap {
				width: 95%;
				margin: 0 auto;
				display: flex;
				align-items: center;
				font-size: 26upx;
				.choose_transfer_left {
					background: #ffffff;
					padding: 10upx 15upx;
					border-radius: 30upx;
				}
				.choose_transfer_middle {
					padding: 0 30upx;
					text {
						color: #1a80da;
					}
				}
				.choose_transfer_right {
					text-align: right;
					color: #1a80da;
				}
				.sreening_wrap {
					width: 500upx;
					height: 100vh;
					background-color: #ffffff;
					.type_obj_str {
						height: 100upx;
						line-height: 100upx;
						text-align: center;
						font-size: 36upx;
						color: #7c7c7c;
						border-bottom: 2upx solid #c0c4cc;
					}
				}
			}
		}
		.card_list_wrap {
			width: 100%;
			// height: 100vh;
			.card_item {
				width: 100%;
				height: 120upx;
				background-color: #ffffff;
				border-bottom: 2upx solid #ededed;
				display: flex;
				align-items: center;
				justify-content: center;
				.card_list {
					width: 90%;
					margin: 0 auto;
					display: flex;
					align-items: center;
					.card_list_left {
						flex: 3;
						.card_name {
							font-size: 24upx;
							padding: 10upx 0;
						}
						.card_num {
							font-size: 36upx;
						}
					}
					.checkbox {
						flex: 1;
						text-align: right;
					}
				}
			}
		}
		.Transfer_bottom {
			width: 100%;
			height: 100upx;
			background: #000000;
			position: fixed;
			left: 0;
			bottom: 0;
			color: #FFFFFF;
			.Transfer_bottom_wrap {
				width: 95%;
				margin: 0 auto;
				height: 100upx;
				display: flex;
				align-items: center;
				justify-content: center;
				.Transfer_bottom_left {
					flex: 1;
				}
				.Transfer_bottom_right {
					flex: 2;
					display: flex;
					align-items: center;
					justify-content: center;
					.total {
						flex: 1;
						display: flex;
						align-items: center;
						justify-content: flex-end;
						text {
							padding-left: 15upx;
						}
					}
					.Transfer_btn_wrap {
						flex: 1;
						width: 100%;
					}
					.Transfer_btn {
						width: 75%;
						margin: 0 auto;
						height: 70upx;
						background-color: #8973f9;
						border-radius: 40upx;
						display: flex;
						align-items: center;
						justify-content: center;
						color: #ffffff;
					}
				}
			}
		}
	}
	.interval_ransfer_box {
		width: 100%;
		margin-top: 120upx;
		background: #ffffff;
		.interval_ransfer {
			width: 95%;
			margin: 0 auto;
			padding: 20upx 0;
			.interval_ransfer_title {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 26upx;
				padding-bottom: 30upx;
				.ransfer_title_left {
					flex: 1;
					display: flex;
					align-items: center;
					justify-content: center;
				}
				.ransfer_title_right {
					flex: 1;
					display: flex;
					align-items: center;
					justify-content: center;
					text {
						color: #1a80da;
						padding: 0 10upx;
					}
				}
			}
			.interval_ransfer_input {
				width: 100%;
				padding: 20upx;
				display: flex;
				align-items: center;
				justify-content: center;
				.ransfer_input_left {
					flex: 1;
				}
				.ransfer_input_right {
					flex: 3;
					width: 100%;
					height: 80upx;
					background: #f5f9fc;
					display: flex;
					align-items: center;
					input {
						padding-left: 20upx;
					}
				}
				.ransfer_input_right1 {
					flex: 3;
					width: 100%;
					height: 200upx;
					background: #f5f9fc;
					display: flex;
					align-items: center;
					textarea {
						width: 100%;
						height: 200upx;
						padding-left: 20upx;
					}
				}
			}
		}
		.interval_ransfer_bottom {
			width: 100%;
			height: 100upx;
			background: #ffffff;
			position: fixed;
			left: 0;
			bottom: 0;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			padding-right: 40upx;
			.interval_ransfer_btn {
				width: 180upx;
				height: 70upx;
				background-color: #8973f9;
				border-radius: 40upx;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #ffffff;
				position: relative;
				overflow: hidden;
				button {
					position: absolute;
					left: 0;
					top: 0;
					width: 180upx;
					height: 70upx;
					opacity: 0;
				}
			}
		}
	}
}
</style>
